<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="shop-info-box">
					<view class="info-item flexWrapNo">
						<view class="flexWrapNo" style="flex: 1;">
							<view class="item-title">门禁开关:</view>
							<picker @change="changeEquipment" :value="deviceIndex" :range="deviceList" range-key="resource_name" v-if="deviceList.length">
								<view class="uni-input">{{deviceList[deviceIndex].resource_name}}</view>
							</picker>
						</view>
						<text class="icon-more"></text>
					</view>
					<view class="info-item flexWrapNo">
						<view class="item-title">开门时间:</view>
						<input placeholder="请输入" placeholder-class="placeholderclass" v-model="store_quick_enty.open_time"/>
						<text>秒</text>
					</view>
					<view class="remaks-box">
						备注：点击开门按钮后，门禁断电开门的时间。超过时间后，大门会自动关闭。
					</view>
				</view>
				<view class="determine-btn" @tap="setOpenDoorPro()">提交保存</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc: 0,
				switchList: [
					{
						name:'累计消费时长',
						id:1
					},
					{
						name:'消费排名',
						id:2
					}
				],
				switchIndex:0,
				store_quick_enty:{},
				// 正向开关列表
				equipment_resources_list:[],
				equipmentIndex:0,
				// 正向选中
				deviceList:[],
				deviceIndex:0,
			}
		},
		onLoad() {
			this.getOpenDoorInfo();
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		methods: {
			changeSwitch(e){
				this.switchIndex = e.detail.value
			},
			getOpenDoorInfo(){
				uni.showLoading({
					title:'加载中，请稍等...',
					mask:true
				})
				this.$request.post(this.$api.getOpenDoorInfo, {
					store_id: uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						this.store_quick_enty=data.store_quick_enty
						this.equipment_resources_list=data.equipment_resources_list
						this.equipmentIndex=this.equipment_resources_list.findIndex(item=>item.did==data.store_quick_enty.did)
						this.deviceList=this.equipment_resources_list[this.equipmentIndex].device_name_list
						this.deviceIndex=this.deviceList.findIndex(item=>item.resource_id==data.store_quick_enty.resources)
					}
				}).finally(() => {
					setTimeout(() => {
						this.$tools.hideLoading()
					}, 1000)
				})
			},
			changeEquipment(e){
				this.deviceIndex=e.detail.value
				this.store_quick_enty.resources=this.deviceList[this.deviceIndex].resource_id
			},
			setOpenDoorPro(){
				let requestData={
					
				}
				requestData=this.store_quick_enty
				this.$request.post(this.$api.setOpenDoorPro,requestData, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						if (res.code==1) {
							this.$tools.showToast('修改成功')
							let pages = getCurrentPages(); //当前页
							let beforePage = pages[pages.length - 2]; //上个页面
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},2000)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 0 36upx;

		.shop-info-box {
			.info-item {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 40upx;
				color: #FFFFFF;
				padding: 30upx 0;
				border-bottom: 1upx solid #36355E;
				picker{
					flex: 1;
				}
				.item-title{
					margin-right: 32upx;
					flex: none;
				}
				.small{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					margin:0 40upx;
				}
				.select-input{
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}
				input {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}

				.icon-more {
					border-color: #FFFFFF;
				}

				.placeholderclass {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
				}
				textarea{
					background: #1D1C5C;
					border-radius: 16upx;
					padding: 30upx;
					height: 140upx;
				}
			}
			.remaks-box{
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #82819B;
				line-height: 40rpx;
				padding-left: 158upx;
				margin-top: 12upx;
			}
		}
		.determine-btn{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			width: 322rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #26BCFD;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 78upx auto;
		}
	}
</style>
